package com.code.day08;

//二分查找

public class Test2 {
    public static void main(String[] args) {
        int[] arr = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
        int result = method(arr);
        System.out.println(result);
    }

    private static int method(int[] arr) {
        int left = 0;
        int right = arr.length - 1;
        int target = 11;

        while (left <= right) {
            int mid = (left + right) / 2;
            if (arr[mid] == target) {
                return mid;
            } else if (arr[mid] > target) {
                right = mid - 1;
            } else {
                left = mid + 1;
            }
        }
        return -1;

    }
}
